package com.gxa.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.common.commons.R;
import com.gxa.order.mapper.TenantMapper;
import com.gxa.order.pojo.hotel.Tenant;
import com.gxa.order.service.TenantService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;

@Service
public class TenantServiceImpl extends ServiceImpl<TenantMapper,Tenant> implements TenantService {

    @Resource
    private TenantMapper tenantMapper;
    private R r;
    /**
     * 添加住客
     * @param tenant
     * @return
     */
    @Override
    public R addTenant(Tenant tenant) {
        R r = new R();
        try{
            int insert = tenantMapper.insert(tenant);
            if(insert>0){
                r.setCode(200);
                r.setMsg("success");
            }
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("系统繁忙");
        }
        return r;
    }

    /**
     * 查询住客信息
     * @param hotelOrderId
     * @return
     */
    @Override
    public List<Tenant> queryTenant(Integer hotelOrderId) {
        QueryWrapper<Tenant> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("hotel_order_id",hotelOrderId);
            List<Tenant> tenants = tenantMapper.selectList(queryWrapper);
            if(tenants!=null){
                return tenants;
            }
        return null;
    }

    /**
     * 修改住客
     * @param tenant
     * @return
     */
    @Override
    public R updateTenant(Tenant tenant) {
        R r = new R();
        try{
            int update = tenantMapper.updateById(tenant);
            if(update>0){
                r.setCode(200);
                r.setMsg("success");
            }
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("系统繁忙");
        }
        return r;
    }

    /**
     * 删除住客
     * @param hotelOrderId
     * @return
     */
    @Override
    public R delTenant(Integer hotelOrderId) {
        R r = new R();
        try{
            int del = tenantMapper.delTenant(hotelOrderId);
            if(del>0){
                r.setCode(200);
                r.setMsg("success");
            }
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("系统繁忙");
        }
        return r;
    }
}
